package com.tanhua.dubbo.server.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.common.exception.BusinessException;
import com.tanhua.common.pojo.User;
import com.tanhua.common.utils.UserThreadLocal;
import com.tanhua.common.vo.ErrorResult;
import com.tanhua.dubbo.server.api.UserLocationApi;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 *
 * @ClassName: BaiduService
 * @Author:王晨晗
 * @Description:
 * @Date: 2022/01/08/17:23
 */
@Service
public class BaiduService {
    @Reference
    private UserLocationApi userLocationApi;

    /**
     * @description 更新用户地理位置
     * @param longitude
     * @param latitude
     * @param address
     * @return
     */
    public void updateLocation(Double longitude, Double latitude, String address) {
        User user = UserThreadLocal.get();
        //Boolean result = userLocationApi.updateUserLocation(user.getId(), longitude, latitude, address);     //es实现
        Boolean result = userLocationApi.updateUserLocation1(user.getId(), longitude, latitude, address);      //mongo实现
        if (!result){
            throw new BusinessException(ErrorResult.userLocationError());   //异常定义 更新用户地理位置错误;
        }
    }
}
